﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;
using System.Drawing;

namespace Helix_Network_Supervisor_3
{
    class Show
    {
        #region Fields

        ApplicationSettings appSettings = new ApplicationSettings();
        VixenXMLParser vixenParser = new VixenXMLParser();
        FileManipulator fm = new FileManipulator();
        //Mp3Reader mp3Reader = new Mp3Reader();
        MP3Header mp3Header = new MP3Header();
        bool showNeedsToBeSaved = false;
        string saveShowFilePath = "";
        string currentShowFileName = "New Show";
        int numberOfSequencesInShow = 0;
        int showTotalTime = 0;
        long showTotalSize = 0;
        int maximumNumberOfChannels = 0;
        bool errorInShow = false;
        int numberOfAvailableSequences = 0;

        #endregion Fields

        #region Ctor

        #endregion Ctor

        #region Properties

        public bool ShowNeedsToBeSaved
        {
            get
            {
                return showNeedsToBeSaved;
            }
        }

        public string CurrentShowFileName
        {
            get
            {
                return currentShowFileName;
            }
        }

        public int NumberOfSequencesInShow
        {
            get
            {
                return numberOfSequencesInShow;
            }
        }

        public string FormatedTotalLength
        {
            get { return ConvertSecondsToFormatedLength(showTotalTime); }
        }

        public int ShowTotalTime
        {
            get
            {
                return showTotalTime;
            }
        }

        public string FormatedTotalSize
        {
            get { return fm.Bytes2MegaBytes(showTotalSize); }
        }

        public long ShowTotalSize
        {
            get
            {
                return showTotalSize;
            }
        }

        public int MaximumNumberOfChannels
        {
            get
            {
                return maximumNumberOfChannels;
            }
        }

        public int NumberOfAvailableSequences
        {
            get { return numberOfAvailableSequences; }
        }

        #endregion Properties

        #region Public Methods

        /// <summary>
        /// Populate the Show List View with the Currently Saved Shows
        /// </summary>
        /// <param name="showListView"></param>
        public void PopulateSavedShowListView(ListView showListView)
        {
            showListView.Clear();

            showListView.Columns.Add("File Name (Double Click to Open)", 200, HorizontalAlignment.Left);
            showListView.Columns.Add("File Path", 1, HorizontalAlignment.Left);

            string showPath = appSettings.showFilePath;

            try
            {
                DirectoryInfo di = new DirectoryInfo(showPath);
                FileInfo[] arrFiles = di.GetFiles();

                string[] listItems = new string[2];
                string fileName = "";
                foreach (FileInfo tempFile in arrFiles)
                {
                    fileName = tempFile.Name;
                    fileName.ToUpper();
                    if (!fileName.Equals("PAGEFILE.SYS"))
                    {
                        //int iImage = 1;
                        //string fileExtension = tempFile.Extension;

                        listItems[0] = fileName;
                        listItems[1] = showPath;

                        ListViewItem lviItem = new ListViewItem(listItems, 1);

                        showListView.Items.Add(lviItem);
                    }
                }
            }
            catch
            {
            }

        }

        /// <summary>
        /// Initialize the Show Controls
        /// </summary>
        /// <param name="showFilesListView"></param>
        /// <param name="showSequencesListView"></param>
        public void InitShowControls(ListView showFilesListView, ListView showSequencesListView, ListView showPauseListView)
        {
            InitFilesListControl(showFilesListView);
            InitSeqListControl(showSequencesListView);
            SetupInitialFileListControl(showFilesListView);
            InitPauseListControl(showPauseListView);
        }

        /// <summary>
        /// Add the Selected Sequence to the Show
        /// </summary>
        /// <param name="showSequencesListView"></param>
        /// <param name="selectedFile"></param>
        /// <param name="insertionIndex"></param>
        /// <returns></returns>
        public bool AddSequenceToShow(ListView showSequencesListView, ListViewItem selectedFile, int insertionIndex)
        {
            if (insertionIndex < 0)
            {
                insertionIndex = 0;
            }

            try
            {
                //ListView.SelectedListViewItemCollection selectedFile = showFilesListView.SelectedItems;

                ListViewItem.ListViewSubItemCollection subItems = selectedFile.SubItems;

                string completePath = subItems[1].Text + @"\" + subItems[0].Text;

                FileInfo fi = new FileInfo(completePath);

                if (fi.Extension == ".vix")
                {
                    int versionNumber = vixenParser.GetVixenVersionSelected(completePath);

                    if (versionNumber != 2)
                    {
                        MessageBox.Show("This is not a valid Vixen file",
                            "Helix Show Builder - Error",
                            MessageBoxButtons.OK, MessageBoxIcon.Stop);
                        return false;
                    } // End if

                    string[] listItems = new string[8];

                    listItems[0] = subItems[0].Text;
                    listItems[1] = completePath;
                    listItems[2] = vixenParser.GetSongTitleFromVixenFile(completePath);
                    listItems[3] = appSettings.vixenV2AudioPath + @"\" + listItems[2];
                    listItems[4] = ConvertSecondsToFormatedLength(vixenParser.GetTimeFromVixenFile(completePath));

                    // Check to make sure the Profile Path has been set

                    int numCh = vixenParser.GetNumberChannelsFromVixenFile(completePath, appSettings.vixenV2ProfilePath);

                    if (numCh <= 0)
                    {
                        MessageBox.Show("Can't determine the number of channels in this sequence.  ",
                            "Sequence Parsing Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);

                        return false;
                    }

                    if (numCh > maximumNumberOfChannels)
                    {
                        maximumNumberOfChannels = numCh;
                    }

                    listItems[7] = numCh.ToString();

                    long seqLength = fi.Length;

                    FileInfo audioFI = new FileInfo(listItems[3]);

                    if (audioFI.Exists)
                    {
                        //if (mp3Header.ReadMP3Information(listItems[3]) == true)
                        //{
                        //    MessageBox.Show("Title:  " + mp3Header.strFileName +
                        //        "\rBit Rate:  " + mp3Header.intBitRate.ToString() +
                        //        "\rLength:  " + mp3Header.strLengthFormatted);
                        //}
                        seqLength += audioFI.Length;
                        listItems[5] = fm.Bytes2MegaBytes(seqLength);
                        listItems[6] = seqLength.ToString();
                        ListViewItem lviItem = new ListViewItem(listItems);

                        showSequencesListView.Items.Insert(insertionIndex, lviItem);

                        //if drag and drop within the Show Sequences List View then delete the original Item
                        if (subItems[2].Text == "showSequencesListView")
                        {
                            try
                            {
                                showSequencesListView.SelectedItems[0].Remove();
                            }
                            catch
                            {

                            }
                        }
                        else
                        {
                            showTotalSize += seqLength;
                            showTotalTime += vixenParser.GetTimeFromVixenFile(completePath);
                        }

                        showNeedsToBeSaved = true;

                        numberOfSequencesInShow = showSequencesListView.Items.Count;

                        return true;
                    } // End if
                    else
                    {
                        MessageBox.Show("The audio file associated with this sequence could not be found.",
                            "Helix Show Builder - Error",
                            MessageBoxButtons.OK, MessageBoxIcon.Stop);
                        return false;
                    } // End else

                } // End if
                else
                {
                    MessageBox.Show("This is not a Vixen File",
                        "Helix Show Builder - Error",
                        MessageBoxButtons.OK, MessageBoxIcon.Stop);

                    return false;
                } // End else
            } // End try
            catch
            {
                MessageBox.Show("No file was selected!", "Helix Show Builder - Error",
                    MessageBoxButtons.OK, MessageBoxIcon.Stop);

                return false;
            } // End catch
        } // End AddSequenceToShow()

        /// <summary>
        /// Delete the Selected Sequence or Pause from the Show
        /// </summary>
        /// <param name="showSequencesListFile"></param>
        public bool DeleteSequenceFromShow(ListView showSequencesListView)
        {
            try
            {
                ListView.SelectedListViewItemCollection selectedFile = showSequencesListView.SelectedItems;

                ListViewItem.ListViewSubItemCollection subItems = selectedFile[0].SubItems;

                int secs = ConvertFormatedLengthToSeconds(subItems[4].Text);

                long size = long.Parse(subItems[6].Text);

                showTotalTime -= secs;
                showTotalSize -= size;

                ListViewItem selectedItem = selectedFile[0];

                selectedItem.Remove();
                numberOfSequencesInShow = showSequencesListView.Items.Count;

                if (numberOfSequencesInShow != 0)
                {
                    ListView.ListViewItemCollection Show = showSequencesListView.Items;
                    maximumNumberOfChannels = 0;
                    foreach (ListViewItem Sequence in Show)
                    {
                        if ((int.Parse(Sequence.SubItems[7].Text)) > maximumNumberOfChannels)
                        {
                            maximumNumberOfChannels = int.Parse(Sequence.SubItems[7].Text);
                        }
                    }
                    showNeedsToBeSaved = true;
                }
                else
                {
                    maximumNumberOfChannels = 0;
                    showNeedsToBeSaved = false;
                }

                //UpdateShowStatusLabel();
                return true;

            } // End try
            catch
            {
                MessageBox.Show("No file was selected", "Helix Show Builder - Error",
                    MessageBoxButtons.OK, MessageBoxIcon.Stop);

                return false;
            } // End catch
        } // End DeleteSequenceFromShow()

        /// <summary>
        /// Add a Pause to the Current Show
        /// </summary>
        /// <param name="showSequencesListView"></param>
        /// <param name="pauseItem"></param>
        /// <param name="insertionIndex"></param>
        /// <returns></returns>
        public bool AddPauseToShow(ListView showSequencesListView, ListViewItem pauseItem, int insertionIndex)
        {
            if (pauseItem.SubItems[0].Text != "Pause")
            {
                return false;
            }

            if (showSequencesListView.Items.Count > 0)
            {
                string[] listItems = new string[8];

                listItems[0] = pauseItem.SubItems[0].Text;
                listItems[1] = "";
                listItems[2] = "---";
                listItems[3] = "";
                listItems[4] = pauseItem.SubItems[1].Text;
                listItems[5] = "";
                listItems[6] = "0";
                listItems[7] = "0";

                ListViewItem lviItem = new ListViewItem(listItems);
                showSequencesListView.Items.Insert(insertionIndex, lviItem);

                if (pauseItem.SubItems[2].Text == "showSequencesListView")
                {
                    showSequencesListView.SelectedItems[0].Remove();
                }

                try
                {
                    int secs = ConvertFormatedLengthToSeconds(pauseItem.SubItems[1].Text);
                    showTotalTime += secs;
                    numberOfSequencesInShow = showSequencesListView.Items.Count;
                }
                catch
                {

                }

                showNeedsToBeSaved = true;
                return true;
            }

            MessageBox.Show("A Pause can't be the first item in a Show.", "Helix Show Builder - Warning",
                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
            return false;
        } // End AddPauseToShow()

        /// <summary>
        /// Open an Existing Show
        /// </summary>
        /// <param name="showSequencesListView"></param>
        /// <param name="openShowFilePath"></param>
        public bool OpenShowFile(ListView showSequencesListView, string openShowFilePath)
        {
            if (showNeedsToBeSaved)
            {
                DialogResult dR = MessageBox.Show("The current show has not been saved.  Save the current show?",
                    "Helix Show Builder Warning", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
                if (dR == DialogResult.Yes)
                {
                    SaveShowFile(showSequencesListView);
                }
                else if (dR == DialogResult.Cancel)
                {
                    return false;
                }
            }

            InitSeqListControl(showSequencesListView);

            saveShowFilePath = openShowFilePath;
            
            ListView.ListViewItemCollection lvicToOpen = fm.OpenShowFile(saveShowFilePath);

            maximumNumberOfChannels = 0;

            foreach (ListViewItem lvi in lvicToOpen)
            {
                //lvi.UseItemStyleForSubItems = false;
                ListViewItem.ListViewSubItemCollection subItems = lvi.SubItems;

                string stringSeconds = subItems[4].Text;

                if (stringSeconds.Length < 7)
                {
                    subItems[4].Text = ConvertSecondsToFormatedLength(int.Parse(stringSeconds));
                    showTotalTime += Int32.Parse(stringSeconds);
                }
                else
                {
                    showTotalTime += ConvertFormatedLengthToSeconds(stringSeconds);
                }
                showSequencesListView.Items.Add((ListViewItem)lvi.Clone());

                showTotalSize += long.Parse(subItems[6].Text);

                int temp = Int32.Parse(subItems[7].Text);
                if (temp > maximumNumberOfChannels)
                {
                    maximumNumberOfChannels = temp;
                }
            }

            numberOfSequencesInShow = showSequencesListView.Items.Count;
            showNeedsToBeSaved = false;
            currentShowFileName = Path.GetFileName(saveShowFilePath);
            return true;
        } // End OpenShowFile()

        /// <summary>
        /// Save the Current Show
        /// </summary>
        /// <param name="showSequencesListView"></param>
        /// <returns></returns>
        public bool SaveShowFile(ListView showSequencesListView)
        {
            if (errorInShow == true)
            {
                MessageBox.Show("A show can't be saved until all of the pause errors are eliminated.", "Helix Show Builder - Warning",
                    MessageBoxButtons.OK, MessageBoxIcon.Warning);

                return (false);
            }

            if (saveShowFilePath == "")
            {
                SaveFileDialog saveFileDialog = new SaveFileDialog();

                saveFileDialog.DefaultExt = "shw";
                saveFileDialog.Filter = "Helix Show Files|*.shw";

                saveFileDialog.InitialDirectory = appSettings.showFilePath;
                //Call the SaveFileDialog
                if (saveFileDialog.ShowDialog() == DialogResult.OK)
                {
                    saveShowFilePath = saveFileDialog.FileName;
                    string fileName = Path.GetFileName(saveShowFilePath);
                    saveShowFilePath = appSettings.showFilePath + @"\" + fileName;
                }
                else
                {
                    return false;
                }
            }

            ListView.ListViewItemCollection lvicToBeSaved = showSequencesListView.Items;

            fm.SaveShow(lvicToBeSaved, saveShowFilePath);
            showNeedsToBeSaved = false;
            currentShowFileName = Path.GetFileName(saveShowFilePath);
            return true;
        }

        /// <summary>
        /// Save the Current Show with a New File Name
        /// </summary>
        /// <param name="showSequencesListView"></param>
        /// <returns></returns>
        public bool SaveAsShow(ListView showSequencesListView)
        {
            if (errorInShow == true)
            {
                MessageBox.Show("A show can't be saved until all of the pause errors are eliminated.", "Helix Show Builder - Warning",
                    MessageBoxButtons.OK, MessageBoxIcon.Warning);

                return (false);
            }

            string originalFilePath = saveShowFilePath;
            saveShowFilePath = "";

            if (SaveShowFile(showSequencesListView) == true)
            {
                return true;
            }
            else
            {
                saveShowFilePath = originalFilePath;
                return false;
            }
        }

        /// <summary>
        /// Create a New Show
        /// </summary>
        /// <param name="showSequencesListView"></param>
        /// <returns></returns>
        public bool NewShow(ListView showSequencesListView)
        {
            if (showNeedsToBeSaved)
            {
                DialogResult dR = MessageBox.Show("The current show has not been saved.  Save the current show?",
                    "Helix Show Builder Warning", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
                if (dR == DialogResult.Yes)
                {
                    SaveShowFile(showSequencesListView);
                }
                else if (dR == DialogResult.Cancel)
                {
                    return false;
                }
            }
            InitSeqListControl(showSequencesListView);

            //UpdateShowStatusLabel();
            return true;
        }

        /// <summary>
        /// Check for Any Pause Errors in the Show
        /// </summary>
        /// <param name="showSequencesListView"></param>
        public void CheckForPauseError(ListView showSequencesListView)
        {
            if (showSequencesListView.Items.Count == 0)
            {
                errorInShow = false;
                return;
            }

            //Clear all Background Colors
            foreach (ListViewItem lvi in showSequencesListView.Items)
            {
                lvi.BackColor = Color.Transparent;
            }

            errorInShow = false;

            //The first item in a Show can't be a Pause
            ListViewItem firstItem = showSequencesListView.Items[0];

            if (firstItem.SubItems[0].Text == "Pause")
            {
                firstItem.BackColor = Color.Red;
                errorInShow = true;

                MessageBox.Show("A Pause can't be the first item in a Show.", "Helix Show Builder - Warning",
                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            //There can't be two pauses in a row
            bool twoPausesInARowError = false;

            if (showSequencesListView.Items.Count > 1)
            {
                for (int index = 0; index < (showSequencesListView.Items.Count - 1); index++)
                {
                    ListViewItem item1 = showSequencesListView.Items[index];
                    ListViewItem item2 = showSequencesListView.Items[index + 1];

                    if ((item1.SubItems[0].Text == "Pause") & (item2.SubItems[0].Text == "Pause"))
                    {
                        item2.BackColor = Color.Red;
                        twoPausesInARowError = true;
                    }
                }

                if (twoPausesInARowError == true)
                {
                    errorInShow = true;
                    MessageBox.Show("There can't be two or more Pauses in a row in a Show.", "Helix Show Builder - Warning",
                        MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }

        }

        /// <summary>
        /// Get the Selected Vixen Sequence From the Show File List View
        /// </summary>
        /// <param name="showFilesListView"></param>
        /// <returns></returns>
        public ListViewItem GetSelectedVixenSequence(ListView showFilesListView)
        {
            try
            {
                ListViewItem lviItem = showFilesListView.SelectedItems[0];

                string[] listItems = new string[4];

                listItems[0] = lviItem.SubItems[0].Text;
                listItems[1] = lviItem.SubItems[1].Text;
                listItems[2] = lviItem.ListView.Name;
                listItems[3] = lviItem.Index.ToString();

                ListViewItem dragItem = new ListViewItem(listItems);

                return dragItem;
            }
            catch
            {
                ListViewItem errorItem = new ListViewItem("error");

                return errorItem;
            }
        }

        /// <summary>
        /// Get the Selected Item From the Show Sequences List View
        /// </summary>
        /// <param name="showSequencesListView"></param>
        /// <returns></returns>
        public ListViewItem GetSelectedShowItem(ListView showSequencesListView)
        {
            try
            {
                ListViewItem lviItem = showSequencesListView.SelectedItems[0];

                string[] itemList = new string[4];

                itemList[0] = lviItem.SubItems[0].Text;

                if (itemList[0] == "Pause")
                {
                    itemList[1] = lviItem.SubItems[4].Text;
                }
                else
                {
                    itemList[1] = appSettings.vixenSeqFilePath;
                }

                itemList[2] = lviItem.ListView.Name;
                itemList[3] = lviItem.Index.ToString();

                ListViewItem dragItem = new ListViewItem(itemList);

                return dragItem;
            }
            catch
            {
                ListViewItem errorItem = new ListViewItem("error");

                return errorItem;
            }
        }

        /// <summary>
        /// Get the Selected Pause From the Show Pause List View
        /// </summary>
        /// <param name="showPauseListView"></param>
        /// <returns></returns>
        public ListViewItem GetSelectedPauseItem(ListView showPauseListView)
        {
            try
            {
                ListViewItem lviItem = showPauseListView.SelectedItems[0];

                string[] listItems = new string[4];

                listItems[0] = "Pause";
                listItems[1] = lviItem.SubItems[1].Text; // Pause Length
                listItems[2] = lviItem.ListView.Name;
                listItems[3] = lviItem.Index.ToString();

                ListViewItem dragItem = new ListViewItem(listItems);

                return dragItem;
            }
            catch
            {
                ListViewItem errorItem = new ListViewItem("error");

                return errorItem;
            }
        }

        #endregion Public Methods

        #region Private Methods

        /// <summary>
        /// Initialize the Available Sequences List View
        /// </summary>
        /// <param name="showFilesListView"></param>
        private void InitFilesListControl(ListView showFilesListView)
        {
            showFilesListView.Clear();
            showFilesListView.Columns.Add("Available Sequences", 180, HorizontalAlignment.Left);
            showFilesListView.Columns.Add("File Path", 0, HorizontalAlignment.Left);
            numberOfAvailableSequences = 0;

        } // End InitFileListControl

        /// <summary>
        /// Initialize the Pause List View
        /// </summary>
        /// <param name="showPauseListView"></param>
        private void InitPauseListControl(ListView showPauseListView)
        {
            showPauseListView.Clear();
            showPauseListView.Columns.Add("Available Pauses", 125, HorizontalAlignment.Left);
            showPauseListView.Columns.Add("Length", 70, HorizontalAlignment.Left);

            string[] listItems = new string[2];

            //Add a 5 Second Pause
            listItems[0] = appSettings.PauseName0;
            //listItems[1] = "00:05";
            listItems[1] = appSettings.PauseLength0;
            ListViewItem lviItem = new ListViewItem(listItems);
            showPauseListView.Items.Add(lviItem);

            //Add a 15 Second Pause
            listItems[0] = appSettings.PauseName1;
            listItems[1] = appSettings.PauseLength1;
            lviItem = new ListViewItem(listItems);
            showPauseListView.Items.Add(lviItem);

            //Add a 30 Second Pause
            listItems[0] = appSettings.PauseName2;
            listItems[1] = appSettings.PauseLength2;
            lviItem = new ListViewItem(listItems);
            showPauseListView.Items.Add(lviItem);

            //Add a 1 Minute Pause
            listItems[0] = appSettings.PauseName3;
            listItems[1] = appSettings.PauseLength3;
            lviItem = new ListViewItem(listItems);
            showPauseListView.Items.Add(lviItem);

            //Add a 5 Minute Pause
            listItems[0] = appSettings.PauseName4;
            listItems[1] = appSettings.PauseLength4;
            lviItem = new ListViewItem(listItems);
            showPauseListView.Items.Add(lviItem);

            //Add a 15 Minute Pause
            listItems[0] = appSettings.PauseName5;
            listItems[1] = appSettings.PauseLength5;
            lviItem = new ListViewItem(listItems);
            showPauseListView.Items.Add(lviItem);
        }

        /// <summary>
        /// Initialize the Show Sequences List View
        /// </summary>
        /// <param name="showSequencesListView"></param>
        private void InitSeqListControl(ListView showSequencesListView)
        {
            //Initialize the columns of the Show Sequence List View
            showSequencesListView.Clear();
            showSequencesListView.Columns.Add("Sequence Name", 155, HorizontalAlignment.Left);
            showSequencesListView.Columns.Add("Sequence Path", 0, HorizontalAlignment.Left);
            showSequencesListView.Columns.Add("Song Name", 155, HorizontalAlignment.Left);
            showSequencesListView.Columns.Add("Song Path", 0, HorizontalAlignment.Left);
            showSequencesListView.Columns.Add("Length", 60, HorizontalAlignment.Right);
            showSequencesListView.Columns.Add("Size", 60, HorizontalAlignment.Right);
            showSequencesListView.Columns.Add("Size (B)", 0, HorizontalAlignment.Right);
            showSequencesListView.Columns.Add("# Channels", 80, HorizontalAlignment.Center);

            showSequencesListView.InsertionMark.Color = Color.Green;
            //Initialize the Show Variables
            numberOfSequencesInShow = 0;
            showTotalTime = 0;
            showTotalSize = 0;
            maximumNumberOfChannels = 0;

            //Initialize the Show Name
            currentShowFileName = "New Show";
            saveShowFilePath = "";

        } // End InitSeqListControl()

        /// <summary>
        /// Load the Show File List View with the Available Sequences
        /// </summary>
        /// <param name="showFilesListView"></param>
        private void SetupInitialFileListControl(ListView showFilesListView)
        {
            try
            {
                DirectoryInfo di = new DirectoryInfo(appSettings.vixenSeqFilePath);
                FileInfo[] arrFiles = di.GetFiles();

                string[] listItems = new string[2];
                string fileName = "";
                foreach (FileInfo tempFile in arrFiles)
                {
                    fileName = tempFile.Name;
                    fileName.ToUpper();
                    if (!fileName.Equals("PAGEFILE.SYS"))
                    {
                        //int iImage = 1;
                        string fileExtension = tempFile.Extension;
                        if (fileExtension == ".vix")
                        {
                            //iImage = 0;
                            numberOfAvailableSequences++;
                        } // End if
                        listItems[0] = fileName;
                        listItems[1] = appSettings.vixenSeqFilePath;

                        ListViewItem lviItem = new ListViewItem(listItems, 1);

                        showFilesListView.Items.Add(lviItem);
                    }
                }
            }
            catch
            {
            }
            //filesStripStatusLabel.Text = "Number of Vixen Files:  " + vixenCount.ToString();
        }

        /// <summary>
        /// Convert a String from the format:  MMm SSs to an Integer Number of Seconds
        /// </summary>
        /// <param name="length"></param>
        /// <returns></returns>
        private int ConvertFormatedLengthToSeconds(string length)
        {
            try
            {
                string stringMinute = length.Substring(0, 2);
                string stringSecond = length.Substring(3, 2);

                int intMinutes = int.Parse(stringMinute);
                int intSeconds = int.Parse(stringSecond);
                return (intSeconds + 60 * intMinutes);
            }
            catch
            {
                return 0;
            }
        }

        /// <summary>
        /// Convert an Interger Number of Seconds to a String with the Format:  MMm SSs
        /// </summary>
        /// <param name="seconds"></param>
        /// <returns></returns>
        private string ConvertSecondsToFormatedLength(int s)
        {
            // Seconds to display
            int ss = s % 60;

            // Complete number of minutes
            int m = (s - ss) / 60;

            // Minutes to display
            int mm = m % 60;

            // Complete number of hours
            int h = (m - mm) / 60;

            // Make "hh:mm:ss"

            if (h > 0)
            {
                return h.ToString("D2") + ":" + mm.ToString("D2") + ":" + ss.ToString("D2");
            }
            else
            {
                return mm.ToString("D2") + ":" + ss.ToString("D2");
            }
        }

        #endregion Private Methods

    }
}
